<template>
  <Modal v-model="modal11" fullscreen title="单据" @on-cancel="cc" @on-ok="ok">
    <div style="background: #eee; padding: 20px">
      <Card :bordered="false">
        <p slot="title" style="text-align: center">{{ billname }}</p>
        <div>
          <Row justify="start">
            <Col span="4">{{ql}}日期:{{ dates }}</Col>
            <Col span="4">{{ql}}单号:{{ didn }}</Col>
            <Col span="2">{{ql}}人员:{{ staff }}</Col>
          </Row>
          <Divider />
          <Table
            :columns="columns15"
            :data="data11"
            border
          ></Table>
          <Table
            :show-header="false"
            :columns="columns16"
            :data="datasum"
            border
          ></Table>
        </div>
      </Card>
    </div>
  </Modal>
</template>
<script>
export default {
  props: {
    datas: Array,
    didn: String,
    billname: String,
    shows: Boolean,
  },
  data() {
    return {
      modal11: false,
      dates: "2021-05-06",
      did: "20210506tx",
      ql:"",
      ss: false,
      datasum: [],
      staff: JSON.parse(sessionStorage.getItem("user")).name,
      columns15: [
        {
          type: "index",
          width: 100,
          align: "center",
        },
        {
          title: "仓库",
          key: "sid",
          align: "center",
        },
        {
          title: "作物",
          key: "name",
          align: "center",
        },
        {
          title: "批次",
          key: "batch",
          align: "center",
        },
        {
          title: "数量",
          key: "num",
          align: "center",
        },
        {
          title: "单价",
          key: "price",
          align: "center",
        },
        {
          title: "合计总价",
          key: "total",
          align: "center",
        },
      ],
      columns16: [
        {
          title: "合计",
          key: "sum",
          width: 100,
          align: "center",
        },
        {
          title: "仓库",
          key: "sid",
          align: "center",
        },
        {
          title: "作物",
          key: "name",
          align: "center",
        },
        {
          title: "批次",
          key: "batch",
          align: "center",
        },
        {
          title: "数量",
          key: "num",
          align: "center",
        },
        {
          title: "单价",
          key: "price",
          align: "center",
        },
        {
          title: "合计总价",
          key: "total",
          align: "center",
        },
      ],
      data11: this.datas,
    };
  },
  mounted() {
    var today = new Date();
    var y = today.getFullYear();
    var m = today.getMonth() + 1;
    var d = today.getDate();
    m = m < 10 ? "0" + m : m;
    d = d < 10 ? "0" + d : d;
    this.dates = y + "-" + m + "-" + d;
  },
  watch: {
    shows: function (nd) {
      this.modal11 = nd;
    },
    datas: {
      handler(nd) {
        this.data11 = nd;
        var count = 0;
        var Tt = 0;
        var row = this.data11[1];
        for (var i in this.data11) {
          row = this.data11[i];
          count += row.num;
          Tt += row.total;
        }
        this.datasum = [
          {
            sum: "合计",
            sid: " ",
            name: " ",
            batch: " ",
            num: count+" 吨",
            price: " ",
            total: Tt+" 万元",
          },
        ];
      },
      deep: true,
    },
    billname(nd){
      this.ql=nd.slice(0,2)
    }
  },
  methods: {
    cc() {
      this.modal11 = false;
      this.$emit("c1", false);
    },
    ok(){
      this.modal11=false
      this.$emit("c2",false)
    }
  },
};
</script>
